//
//  PEMChallengeListCell.swift
//  PhaseExcitedMotion
//
//  Created by iOS-Czz on 2023/11/14.
//

import UIKit
import KFGradientProgressView

class PEMChallengeListCell: UICollectionViewCell {

    @IBOutlet var progressView: GradientProgressView!
    @IBOutlet var completedIcon: UIImageView!
    @IBOutlet var infoLabel: UILabel!
    @IBOutlet var dateLabel: UILabel!
    @IBOutlet var nameLabel: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    var model: PEMChallengeModel? {
        didSet {
            self.nameLabel.text = model?.name
            self.dateLabel.text = model?.date
            progressView.layer.cornerRadius = 3
            progressView.progressCornerRadius = 3
            progressView.progressColors = [.green]
            progressView.animationDuration = 1
            progressView.timingFunction = CAMediaTimingFunction(name: .default)
            /// 0 duration 1 distance 2 step 3 energy
            var str = ""
            switch model?.type {
            case 0:
                str = "h"
            case 1:
                str = "m"
            case 2:
                str = ""
            case 3:
                str = "kcal"
            default:
                break
            }
            self.infoLabel.text = String(format: "%.0f%@/%.0f%@", model!.progress,str,model!.target,str)
            progressView.setProgress(Float(model!.progress / model!.target), animated: true)
            self.completedIcon.image = UIImage(named: model!.completed ? "bg_challenge_completed":"bg_challenge_uncompleted")
        }
    }
}
